package com.neuedu.corejava.ch12;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 
 * @author myh
 * @version 2019年8月13日下午2:24:17
 *
 */
public class FilesClass {

	public static void main(String[] args) {
		//在C盘根目录下创建一个文件abc.txt
		String fileName = "c:\\abc.txt";
		Path path = Paths.get(fileName);
		try {
			Path file = Files.createFile(path);
			System.out.println(file.getFileName());
			
			
			//把文件拷贝到D盘根目录下
			Path destPath = Paths.get("d:\\abc.txt");
			Files.copy(path, destPath);
			System.out.println("拷贝成功");
			
			//把D盘根目录下abc.txt剪切到C盘根目录下，并重命名为abcd.txt
			Path destPath2 = Paths.get("c:\\abcd.txt");
			Files.move(destPath, destPath2);
			System.out.println("剪切成功");
			
			//删除abcd.txt
			Files.deleteIfExists(path);
			Files.deleteIfExists(destPath2);
			System.out.println("删除成功");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		

	}

}
